﻿Public Class frm_NewPrice
#Region "Khai báo biến"
    Dim mvBol_Close As Boolean = False
    Public gvDbl_Quantity As Double
    Public gvDbl_Price As Double
    Dim mvUrc_Caculator As New urc_Calculator()
    Dim mvByte_Flag As Byte 'Biến lưu trạng thái textbox đang active : 1 = txtQuantity, 2 = txtPrice
#End Region
#Region "Hàm khởi tạo"
    Private Sub SubM_InitializeForm()
        AddHandler mvUrc_Caculator.txtInput.TextChanged, AddressOf txtInput_TextChanged
        mod_Format.Sub_ShowControl(mvUrc_Caculator, 27)
        Me.mvBol_Close = False
        mvUrc_Caculator.txtInput.Text = Me.txtQuantity.Text
        Me.txtPrice.Text = mvUrc_Caculator.txtInput.Text
        Me.txtPrice.BackColor = Color.LightSkyBlue
        Me.txtQuantity.BackColor = Color.White
        mvByte_Flag = 2
    End Sub
#End Region
#Region "Form events"
    Private Sub frm_DiscountServiceVat_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If Not mvBol_Close Then
            e.Cancel = True
        End If
    End Sub
    Private Sub frm_DiscountServiceVat_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SubM_InitializeForm()
    End Sub
#End Region
#Region "Change textbox focus"
    Private Sub ActiveFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPrice.Enter, txtQuantity.Enter
        Try
            Dim mvCtr_ActiveControl As New Control
            mvCtr_ActiveControl = Form.ActiveForm.ActiveControl.Parent
            If mvCtr_ActiveControl.Name = "txtQuantity" Then
                Me.txtQuantity.BackColor = Color.LightSkyBlue
                Me.txtPrice.BackColor = Color.White
                mvByte_Flag = 1
            ElseIf mvCtr_ActiveControl.Name = "txtPrice" Then
                Me.txtQuantity.BackColor = Color.White
                Me.txtPrice.BackColor = Color.LightSkyBlue
                mvByte_Flag = 2
            End If
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Textchange"
    Private Sub txtInput_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim mvDbl_Quantity As Double = 0
        Dim mvDbl_Price As Double = 0
        Try
            If mvByte_Flag = 1 Then
                Me.txtQuantity.Text = mvUrc_Caculator.txtInput.Text
            Else
                Me.txtPrice.Text = mvUrc_Caculator.txtInput.Text
            End If
            If IsNumeric(Me.txtQuantity.Text) Then
                mvDbl_Quantity = Convert.ToDouble(Me.txtQuantity.Text)
            End If
            If IsNumeric(Me.txtPrice.Text) Then
                mvDbl_Price = Convert.ToDouble(Me.txtPrice.Text)
            End If
            Me.txtTotal.Text = mvDbl_Quantity * mvDbl_Price
            If gvByte_Language = 1 Then
                SubG_FormatNumberDigit(Me.txtTotal, 0)
            Else
                SubG_FormatNumberDigit(Me.txtTotal, 2)
            End If
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Nút confirm"
    Private Sub cmdConfirm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConfirm.Click
        Try
            If Not IsNumeric(mvUrc_Caculator.txtInput.Text) Then
                FunG_Alert("Thông báo lỗi!", "Yêu cầu nhập số!", frm_Alert.WTYPE.ERROR)
            Else
                gvDbl_Quantity = Me.txtQuantity.Text
                gvDbl_Price = Me.txtPrice.Text
                mvBol_Close = True
                Me.Close()
            End If
        Catch ex As Exception

        End Try
    End Sub
#End Region
#Region "Nút exit"
    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        gvDbl_Quantity = 0
        mvBol_Close = True
        Me.Close()
    End Sub
#End Region
End Class